import api from './index';

// 获取数据库连接状态
export const getDatabaseStatus = (taskId) => {
  return api.post('db/status', { 
    task_id: taskId
  });
};

// 执行SQL查询
export const executeQuery = (taskId, query) => {
  return api.post('db/query', {
    task_id: taskId,
    query: query
  });
};

// 获取数据库表结构
export const getTableStructure = (taskId, tableName) => {
  return api.post('db/table-structure', {
    task_id: taskId,
    table_name: tableName
  });
};

// 获取表列表
export const getTables = (taskId) => {
  return api.post('db/tables', {
    task_id: taskId
  });
};

// 执行数据库变更SQL(INSERT/UPDATE/DELETE/ALTER等)
export const executeUpdate = (taskId, sql) => {
  return api.post('db/update', {
    task_id: taskId,
    sql: sql
  });
};

// 创建表
export const createTable = (taskId, createTableSql) => {
  return api.post('db/create-table', {
    task_id: taskId,
    create_table_sql: createTableSql
  });
};

// 获取项目数据库连接
export const getProjectDatabaseConnections = (projectId) => {
  return api.get(`db/connections/${projectId}`);
};

// 创建数据库连接配置
export const createDatabaseConnection = (connectionData, projectId = null) => {
  return api.post('db/connections', {
    connection_data: connectionData,
    project_id: projectId
  });
};

// 测试数据库连接
export const testDatabaseConnection = (connectionData) => {
  return api.post('db/test-connection', {
    connection_data: connectionData
  });
}; 